// libavcodec/avcodec.h
struct AVCodecContext {
    ...
    /**
     * Additional data associated with the entire coded stream.
     *
     * - decoding: unused
     * - encoding: may be set by libavcodec after avcodec_open2().
     */
    AVPacketSideData *coded_side_data;
    int            nb_coded_side_data;

    int samples_to_skip;
};

// libavcodec/apedec.c
ape_decode_frame()
{
    ...

    int skip = FFMIN(avctx->samples_to_skip, blockstodecode);
    switch (s->bps) {
    case 8:
        for (ch = 0; ch < s->channels; ch++) {
            sample8 = (uint8_t *)frame->data[ch];
            // for (i = 0; i < blockstodecode; i++)
            for (i = skip; i < blockstodecode; i++)
                *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff;
        }
        break;
    case 16:
        for (ch = 0; ch < s->channels; ch++) {
            sample16 = (int16_t *)frame->data[ch];
            // for (i = 0; i < blockstodecode; i++)
            for (i = skip; i < blockstodecode; i++)
                *sample16++ = s->decoded[ch][i];
        }
        break;
    case 24:
        for (ch = 0; ch < s->channels; ch++) {
            sample24 = (int32_t *)frame->data[ch];
            // for (i = 0; i < blockstodecode; i++)
            for (i = skip; i < blockstodecode; i++)
                *sample24++ = s->decoded[ch][i] << 8;
        }
        break;
    }

    avctx->samples_to_skip -= skip;
    s->samples -= blockstodecode;

    *got_frame_ptr = avctx->samples_to_skip > 0 ? 0 : 1;

    ...
}


// libavformat/ape.c
ape_read_seek()
{
    ...
    AVCodecContext *codec = st->codec;

    int64_t micro_second = av_rescale_q(timestamp, st->time_base, AV_TIME_BASE_Q);
    uint32_t wanted_samples = ape->samplerate * (micro_second / 1000000);
    uint32_t samples = index * ape->blocksperframe;
    int samplestoskip = wanted_samples - samples;

    av_log(NULL, AV_LOG_ERROR, "micro second: %lld, wanted sample: %lu, sample: %lu, skip: %d",
           micro_second, wanted_samples, samples, samplestoskip);

    if (samplestoskip < 0)
        samplestoskip = 0;

    codec->samples_to_skip = samplestoskip;

    ...
}
